package cn.edu.xmu.orderpayment.payment.model.bo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Guanlin Wang 22920192204282
 * @date 2021/12/12
 */
@NoArgsConstructor
@AllArgsConstructor
@Data
public class Payment {
    /**
     * 支付单状态
     */
    public enum State{
        PENDING_PAYMENT((byte)0 ,"待支付"),
        PAYMENT_COMPLETED((byte)1,"已支付"),
        RECONCILIATION_COMPLETED((byte)2, "已对账"),
        LIQUIDATION_COMPLETED((byte)3, "已清算"),
        PAYMENT_FAILED((byte)4, "支付失败"),
        CANCELED((byte)5, "取消");


        private static final Map<Byte, State> stateMap;
        static {
            stateMap = new HashMap();
            for (State enum1 : values()) {
                stateMap.put(enum1.code, enum1);
            }
        }

        private Byte code;
        private String description;
        State(Byte code, String description) {
            this.code = code;
            this.description = description;
        }


        public Byte getCode() {
            return this.code;
        }

        public String getDescription() {
            return this.description;
        }
        public static State getStateByCode(Integer code) {
            return stateMap.get(code);
        }
    }

    public DocumentType getDocumentType() {
        return DocumentType.getDocumentTypeByCode(Integer.valueOf(documentType));
    }
    public void setDocumentType( DocumentType documentType) {
        this.documentType=documentType.getCode().byteValue();
    }

    public enum DocumentType{
        NORMAL(0,"订单"),
        BOND(1,"保证金"),
        AFTERSALE(2,"售后");
        private static final Map<Integer,  DocumentType> DOCUMENT_TYPE_MAP;
        static {
            DOCUMENT_TYPE_MAP = new HashMap();
            for (Payment.DocumentType enum1 : values()) {
                DOCUMENT_TYPE_MAP.put(enum1.code, enum1);
            }
        }
        private int code;
        private String description;
        DocumentType(int code, String description) {
            this.code = code;
            this.description = description;
        }
        public static  DocumentType getDocumentTypeByCode(Integer code) {
            return DOCUMENT_TYPE_MAP.get(code);
        }
        public Integer getCode() {
            return code;
        }
        public String getDescription() {
            return description;
        }
    }

    private Long id;// 支付id
    private String tradeSn;// 交易流水号
    private Long patternId;// 交易渠道id
    private Long amount;// 支付金额
    private Long actualAmount;// 实际支付金额
    private String documentId;// 单据id
    private Byte documentType;//单据类型 0 订单，1 保证金，2 订单订金， 3 订单尾款
    private LocalDateTime payTime;// 实际支付时间
    private LocalDateTime beginTime;// 开始支付时间
    private LocalDateTime endTime;// 结束支付时间
    private Byte state;// 状态
    private String descr;// 备注
    private Long adjustId;
    private String adjustName;
    private Long creatorId;
    private String creatorName;
    private Long modifierId;
    private String modifierName;
    private LocalDateTime adjustTime;// 调账时间
    private LocalDateTime gmtCreate;// 创建时间
    private LocalDateTime gmtModified;// 修改时间

    //自动生成getter/setter方法
    public  State getState() {
        return  State.getStateByCode(Integer.valueOf(state));
    }
    public void setState( State state) {
        this.state=state.getCode().byteValue();
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getTradeSn() {
        return tradeSn;
    }

    public void setTradeSn(String tradeSn) {
        this.tradeSn = tradeSn;
    }

    public Long getPatternId() {
        return patternId;
    }

    public void setPatternId(Long patternId) {
        this.patternId = patternId;
    }

    public Long getAmount() {
        return amount;
    }

    public void setAmount(Long amount) {
        this.amount = amount;
    }

    public Long getActualAmount() {
        return actualAmount;
    }

    public void setActualAmount(Long actualAmount) {
        this.actualAmount = actualAmount;
    }

    public String getDocumentId() {
        return documentId;
    }

    public void setDocumentId(String documentId) {
        this.documentId = documentId;
    }

    public void setDocumentType(Byte documentType) {
        this.documentType = documentType;
    }

    public LocalDateTime getPayTime() {
        return payTime;
    }

    public void setPayTime(LocalDateTime payTime) {
        this.payTime = payTime;
    }

    public LocalDateTime getBeginTime() {
        return beginTime;
    }

    public void setBeginTime(LocalDateTime beginTime) {
        this.beginTime = beginTime;
    }

    public LocalDateTime getEndTime() {
        return endTime;
    }

    public void setEndTime(LocalDateTime endTime) {
        this.endTime = endTime;
    }

    public void setState(Byte state) {
        this.state = state;
    }

    public String getDescr() {
        return descr;
    }

    public void setDescr(String descr) {
        this.descr = descr;
    }


    public LocalDateTime getAdjustTime() {
        return adjustTime;
    }

    public void setAdjustTime(LocalDateTime adjustTime) {
        this.adjustTime = adjustTime;
    }

    public LocalDateTime getGmtCreate() {
        return gmtCreate;
    }

    public void setGmtCreate(LocalDateTime gmtCreate) {
        this.gmtCreate = gmtCreate;
    }

    public LocalDateTime getGmtModified() {
        return gmtModified;
    }

    public void setGmtModified(LocalDateTime gmtModified) {
        this.gmtModified = gmtModified;
    }
}
